home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1997 #3 / Amiga Plus CD - 1997 - No. 03.iso / pd / programmierung / vbcc / opt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  23.8 KB  |  571 lines

  1. /*  $VER: vbcc (opt.c) V0.4     */
  2. /*  allgemeine Routinen fuer den Optimizer und Steuerung der einzelnen  */
  3. /*  Laeufe                                                              */
  4.  
  5. #include "opt.h"
  6.  
  7. static char FILE_[]=__FILE__;
  8.  
  9. /*  die naechsten Funktionen sollten evtl. in ic.c                  */
  10.  
  11. /*  Sind use/change-Listen initialisiert?   */
  12. int have_alias;
  13.  
  14. void insert_IC(struct IC *p,struct IC *new)
  15. /*  fuegt new hinter p ein; p darf 0 sein                           */
  16. {
  17.     new->prev=p;
  18.     if(p){ new->next=p->next; p->next=new; }
  19.      else{ new->next=first_ic; first_ic=new; }
  20.     if(new->next) new->next->prev=new; else last_ic=new;
  21.     new->q1.am=new->q2.am=new->z.am=0;
  22. }
  23.  
  24. #ifndef NO_OPTIMIZER
  25.  
  26. int gchanged;   /*  Merker, ob Optimierungslauf etwas geaendert hat */
  27. int norek;      /*  diese Funktion wird nicht rekursiv auf          */
  28. int nocall;     /*  diese Funktion kehrt nicht zum Caller zurueck   */
  29.  
  30. /*  temporary fuer verschiedene Bitvektoren */
  31. unsigned char *tmp;
  32.  
  33. void recalc_offsets(struct flowgraph *fg)
  34. /*  berechnet Offsets fuer auto-Variablen neu und versucht, fuer Variablen, */
  35. /*  die nicht gleichzeitig aktiv sind, den gleichen Platz zu belegen        */
  36. {
  37.     int i,b,*eqto;size_t bsize;zlong *al,*sz;
  38.     unsigned char **used,*tmp,*empty;
  39.     struct IC *p;
  40.     if(DEBUG&1024) printf("recalculating offsets\n");
  41.     if(DEBUG&1024) printf("setting up arrays\n");
  42.     bsize=(basic_blocks+CHAR_BIT-1)/CHAR_BIT;
  43.     if(DEBUG&1024) printf("bsize=%lu\n",(unsigned long)bsize);
  44.     tmp=mymalloc(bsize);
  45.     al=mymalloc(sizeof(*al)*(vcount-rcount));
  46.     eqto=mymalloc(sizeof(int)*(vcount-rcount));
  47.     sz=mymalloc(sizeof(*sz)*(vcount-rcount));
  48.     empty=mymalloc(bsize);
  49.     memset(empty,0,bsize);
  50.     used=mymalloc(sizeof(unsigned char *)*(vcount-rcount));
  51.     /*  Tabelle, welche Variable in welchem Block belegt ist, aufbauen  */
  52.     for(i=0;i<vcount-rcount;i++){
  53.         if(zlleq(l2zl(0L),vilist[i]->offset)&&(vilist[i]->storage_class==AUTO||vilist[i]->storage_class==REGISTER)){
  54.             if(DEBUG&2048) printf("setting up for %s,%ld\n",vilist[i]->identifier,zl2l(vilist[i]->offset));
  55.             used[i]=mymalloc(bsize);
  56.             memset(used[i],0,bsize);
  57.         }else{
  58.             used[i]=0;
  59.         }
  60.         sz[i]=szof(vilist[i]->vtyp);
  61.         al[i]=align[vilist[i]->vtyp->flags&15]; /*  noch fuer Arrays aendern */
  62.         eqto[i]=-1;
  63.     }
  64.     b=0;
  65.     while(fg){
  66.         if(b>=basic_blocks) ierror(0);
  67.         for(i=0;i<vcount-rcount;i++){
  68.             if(used[i]&&(BTST(fg->av_in,i)||BTST(fg->av_out,i))){
  69.                 int r;
  70.                 BSET(used[i],b);
  71.                 for(r=1;r<=MAXR;r++)
  72.                     if(fg->regv[r]&&fg->regv[r]->index==i) BCLR(used[i],b);
  73.             }
  74.         }
  75.         for(p=fg->start;p;p=p->next){
  76.             if((p->q1.flags&(VAR|REG))==VAR){
  77.                 i=p->q1.v->index;
  78.                 if(used[i]){
  79.                     BSET(used[i],b);
  80.                 }
  81.             }
  82.             if((p->q2.flags&(VAR|REG))==VAR){
  83.                 i=p->q2.v->index;
  84.                 if(used[i]){
  85.                     BSET(used[i],b);
  86.                 }
  87.             }
  88.             if((p->z.flags&(VAR|REG))==VAR){
  89.                 i=p->z.v->index;
  90.                 if(used[i]){
  91.                     BSET(used[i],b);
  92.                 }
  93.             }
  94.             if(p==fg->end) break;
  95.         }
  96.         fg=fg->normalout;
  97.         b++;
  98.     }
  99.     /*  schauen, ob Variablen in gleichen Speicher koennen  */
  100.     if(DEBUG&1024) printf("looking for distinct variables\n");
  101.     for(i=0;i<vcount-rcount;i++){
  102.         if(!used[i]||eqto[i]>=0) continue;
  103.         if(!memcmp(used[i],empty,bsize)){ free(used[i]);used[i]=0;continue;}
  104.         for(b=i+1;b<vcount-rcount;b++){
  105.             if(!used[b]||eqto[b]>=0) continue;
  106.             if(DEBUG&2048) printf("comparing %s(%ld) and %s(%ld)\n",vilist[i]->identifier,zl2l(vilist[i]->offset),vilist[b]->identifier,zl2l(vilist[b]->offset));
  107.  
  108.             memcpy(tmp,used[i],bsize);
  109.             bvintersect(tmp,used[b],bsize);
  110.             if(!memcmp(tmp,empty,bsize)){
  111.                 if(DEBUG&1024) printf("memory for %s(%ld) and %s(%ld) equal\n",vilist[i]->identifier,zl2l(vilist[i]->offset),vilist[b]->identifier,zl2l(vilist[b]->offset));
  112.                 eqto[b]=i;
  113.                 if(!zlleq(al[b],al[i])) al[i]=al[b];
  114.                 if(!zlleq(sz[b],sz[i])) sz[i]=sz[b];
  115.                 bvunite(used[i],used[b],bsize);
  116.             }
  117.         }
  118.     }
  119.     if(DEBUG&1024) printf("final recalculating\n");
  120.     max_offset=l2zl(0L);
  121.     for(i=0;i<vcount-rcount;i++){
  122.         if(!used[i]) continue;
  123.         free(used[i]);
  124.         if(DEBUG&2048) printf("adjusting offset for %s,%ld\n",vilist[i]->identifier,zl2l(vilist[i]->offset));
  125.         if(eqto[i]>=0){
  126.             vilist[i]->offset=vilist[eqto[i]]->offset;
  127.             continue;
  128.         }
  129.         vilist[i]->offset=zlmult(zldiv(zladd(max_offset,zlsub(al[i],l2zl(1L))),al[i]),al[i]);
  130.         max_offset=zladd(vilist[i]->offset,sz[i]);
  131.     }
  132.     free(used);
  133.     free(sz);
  134.     free(al);
  135.     free(tmp);
  136.     free(empty);
  137.     free(eqto);
  138. }
  139. void remove_IC_fg(struct flowgraph *g,struct IC *p)
  140. /*  Entfernt IC p und beachtet Flussgraph. Ausserdem werden             */
  141. /*  use/change-Listen freigegeben.                                      */
  142. {
  143.     if(p->q1.am||p->q2.am||p->z.am) ierror(0);
  144.     if(have_alias){
  145.         free(p->use_list);
  146.         free(p->change_list);
  147.     }
  148.     if(g->start==g->end){
  149.         g->start=g->end=0;
  150.     }else{
  151.         if(p==g->end) g->end=p->prev;
  152.         if(p==g->start) g->start=p->next;
  153.     }
  154.     remove_IC(p);
  155. }
  156.  
  157. int peephole(void)
  158. /*  macht alle moeglichen Vereinfachungen/Vereinheitlichungen   */
  159. {
  160.     struct IC *p;struct obj o;int t,c,null,eins,changed,done=0;
  161.     do{
  162.         if(DEBUG&1024) printf("searching for peephole optimizations\n");
  163.         changed=0;ic_count=0;
  164.         p=first_ic;
  165.         while(p){
  166.             c=p->code;
  167.             t=p->typf;
  168.             ic_count++;
  169.             if(p->q1.flags&KONST){
  170.                 if((p->q2.flags&KONST)||!p->q2.flags){
  171.                     struct IC *old=p->prev;
  172.                     if(fold(p)){ changed=1; p=old;continue;}
  173.                     p=p->next;continue;
  174.                 }else{
  175.                     if(c==ADD||c==MULT||(c>=OR&&c<=AND)){ /*  const nach rechts   */
  176.                         if(DEBUG&1024){ printf("swapped commutative op:\n");pric2(stdout,p);}
  177.                         o=p->q1;p->q1=p->q2;p->q2=o;
  178.                     }
  179.                 }
  180.             }
  181.             if(p->q2.flags&KONST){
  182.             /*  algebraische Optimierungen  */
  183.                 eval_const(&p->q2.val,t);
  184.                 if(zleqto(vlong,l2zl(0L))&&zuleqto(vulong,ul2zul(0UL))&&zdeqto(vdouble,d2zd(0.0))) null=1; else null=0;
  185.                 if(zleqto(vlong,l2zl(1L))&&zuleqto(vulong,ul2zul(1UL))&&zdeqto(vdouble,d2zd(1.0))) eins=1; else eins=0;
  186.                 if(zleqto(vlong,l2zl(-1L))&&zdeqto(vdouble,d2zd(-1.0))) eins=-1;
  187.                 if(eins<0&&(c==MULT||c==DIV)){
  188.                     if(DEBUG&1024){ printf("MULT/DIV with (-1) converted to MINUS:\n");pric2(stdout,p);}
  189.                     p->code=c=MINUS;p->q2.flags=0;
  190.                     changed=1;
  191.                 }
  192. #if 0
  193.                 if(c==SUB){
  194.                 /*  VORSICHT: Das funktioniert bei bestimmten Werten nicht! */
  195.                     if(DEBUG&1024){ printf("SUB converted to ADD:\n");pric2(stdout,p);}
  196.                     p->code=c=ADD; calc(MINUS,t,&p->q2.val,0,&p->q2.val,p);
  197.                     changed=1;
  198.                 }
  199. #endif
  200.                 if((eins>0&&(c==MULT||c==DIV))||(null&&(c==ADD||c==SUB||c==ADDI2P||c==SUBIFP||c==LSHIFT||c==RSHIFT||c==OR||c==XOR))){
  201.                     if(DEBUG&1024){ printf("operation converted to simple assignment:\n");pric2(stdout,p);}
  202.                     if(c==ADDI2P||c==SUBIFP) p->typf=t=POINTER;
  203.                     p->code=c=ASSIGN;p->q2.flags=0;p->q2.val.vlong=sizetab[t&15];
  204.                     changed=1;
  205.                 }
  206.                 if(null&&(c==MULT||c==DIV||c==MOD||c==AND)){
  207.                     if(c==DIV||c==MOD){ err_ic=p;error(210);err_ic=0;}
  208.                     if(DEBUG&1024){ printf("operation converted to ASSIGN 0:\n");pric2(stdout,p);}
  209.                     o.val.vlong=l2zl(0L);eval_const(&o.val,LONG);
  210.                     insert_const2(&p->q1.val,t);p->q1.flags=KONST;
  211.                     p->code=c=ASSIGN;p->q2.flags=0;p->q2.val.vlong=sizetab[t&15];
  212.                     changed=1;
  213.                 }
  214.                 if(((t&15)<=LONG||(c_flags[21]&USEDFLAG))&&(c==ADD||c==ADDI2P||c==MULT||c==LSHIFT||c==RSHIFT||c==OR||c==AND)){
  215.                 /*  assoziative Operatoren  */
  216.                     struct IC *n=p->next;
  217.                     if(n&&n->code==c&&(n->q2.flags&KONST)&&n->typf==t&&n->q1.flags==p->z.flags&&n->q1.v==p->z.v&&zleqto(n->q1.val.vlong,p->z.val.vlong)){
  218.                         if(DEBUG&1024){ printf("using associativity with:\n");pric2(stdout,p);pric2(stdout,p->next);}
  219.                         n->q1=p->q1;
  220.                         if(c==LSHIFT||c==RSHIFT||c==ADDI2P)
  221.                             calc(ADD,t,&p->q2.val,&n->q2.val,&n->q2.val,0);
  222.                         else
  223.                             calc(c,t,&p->q2.val,&n->q2.val,&n->q2.val,0);
  224.                         changed=1;
  225.                         if(p->q1.flags==p->z.flags&&p->q1.v==p->z.v&&zleqto(p->q1.val.vlong,p->z.val.vlong)){
  226.                             if(DEBUG&1024) printf("must remove first operation\n");
  227.                             n=p;p=p->next;
  228.                             if(have_alias){ free(n->use_list); free(n->change_list); }
  229.                             remove_IC(n);continue;
  230.                         }
  231.                     }
  232.                 }
  233.                 if((c==ADDI2P||c==SUBIFP)&&(p->q1.flags&VARADR)){
  234.                 /*  add #var,#const -> move #var+const      */
  235.                     union atyps val;
  236.                     if(DEBUG&1024){printf("add/sub #var,#const changed to assign:\n");pric2(stdout,p);}
  237.                     eval_const(&p->q2.val,t);
  238.                     insert_const2(&val,LONG);
  239.                     if(c==ADDI2P) calc(ADD,LONG,&p->q1.val,&val,&p->q1.val,0);
  240.                         else      calc(SUB,LONG,&p->q1.val,&val,&p->q1.val,0);
  241.                     p->code=c=ASSIGN;
  242.                     p->q2.flags=0;
  243.                     p->typf=t=POINTER;
  244.                     p->q2.val.vlong=sizetab[t&15];
  245.                     changed=1;
  246.                 }
  247.                 if((c==ADD||c==SUB)&&(t&15)<=LONG&&p->next&&p->next->next){
  248.                     struct IC *p1=p->next,*p2=p1->next;
  249.                     if(p1->code==MULT&&p2->code==ADDI2P&&
  250.                        p1->typf==t&&p2->typf==t&&
  251.                        (p1->q2.flags&KONST)&&(p->z.flags&SCRATCH)&&(p1->z.flags&SCRATCH)&&
  252.                        !compare_objs(&p->z,&p1->q1,t)&&
  253.                        !compare_objs(&p1->z,&p2->q2,t)){
  254.                         if(DEBUG&1024){ printf("rearranging array-access:\n");pric2(stdout,p);pric2(stdout,p1);pric2(stdout,p2);}
  255.                         p1->q1=p->q1;
  256.                         p->q1=p2->q1;
  257.                         p2->q1=p2->z;
  258.                         p->z=p2->z;
  259.                         calc(MULT,t,&p->q2.val,&p1->q2.val,&p->q2.val,0);
  260.                         if(c==ADD) p->code=ADDI2P; else p->code=SUBIFP;
  261.                         changed=1;continue;
  262.                     }
  263.                 }
  264.             }
  265.             if(p->q1.flags&KONST){
  266.             /*  algebraische Optimierungen  */
  267.                 eval_const(&p->q1.val,t);
  268.                 if(zleqto(vlong,l2zl(0L))&&zuleqto(vulong,ul2zul(0UL))&&zdeqto(vdouble,d2zd(0.0))) null=1; else null=0;
  269.                 if(null&&(c==DIV||c==MOD||c==LSHIFT||c==RSHIFT)){
  270.                     if(DEBUG&1024){ printf("operation converted to ASSIGN 0:\n");pric2(stdout,p);}
  271.                     o.val.vlong=l2zl(0L);eval_const(&o.val,LONG);
  272.                     insert_const2(&p->q1.val,t);p->q1.flags=KONST;
  273.                     p->code=c=ASSIGN;p->q2.flags=0;p->q2.val.vlong=sizetab[t&15];
  274.                     changed=1;
  275.                 }
  276.             }
  277.             if(!USEQ2ASZ&&p->z.flags&&!compare_objs(&p->q2,&p->z,p->typf)){
  278.                 if(c==ADD||c==MULT||(c>=OR&&c<=AND)){
  279.                     struct obj o;
  280.                     if(DEBUG&1024){printf("swapping objs because USEQ2ASZ\n");pric2(stdout,p);}
  281.                     o=p->q2;p->q2=p->q1;p->q1=o;
  282.                     /*  kein changed hier!  */
  283.                 }else{pric2(stdout,p); ierror(0);}
  284.             }
  285.             if((c==ADD||c==SUB)&&p->next){
  286.                 struct IC *p1=p->next;
  287.                 if(p1->code==ADDI2P&&p1->typf==t&&(p->z.flags&SCRATCH)&&!compare_objs(&p->z,&p1->q2,t)){
  288.                     if(DEBUG&1024){ printf("rearranging array-access:\n");pric2(stdout,p);pric2(stdout,p1);}
  289.                     p1->q2=p->q1;
  290.                     p->q1=p1->q1;
  291.                     p->z=p1->z;
  292.                     p1->q1=p1->z;
  293.                     if(c==ADD) p->code=c=ADDI2P; else p->code=c=SUBIFP;
  294.                     changed=1;continue;
  295.                 }
  296.             }
  297.             if((c==SUB||c==DIV||c==MOD)&&!compare_objs(&p->q1,&p->q2,p->typf)){
  298.                 /*  x-x=0, x/x=1, x%x=0 */
  299.                 if(DEBUG&1024){ printf("i-i, i/i, i%%i converted to ASSIGN 0/1:\n");pric2(stdout,p);}
  300.                 if(c==DIV) o.val.vlong=l2zl(1L); else o.val.vlong=l2zl(0L);
  301.                 eval_const(&o.val,LONG);insert_const2(&p->q1.val,t);p->q1.flags=KONST;
  302.                 p->code=c=ASSIGN;p->q2.flags=0;p->q2.val.vlong=sizetab[t&15];
  303.                 changed=1;
  304.             }
  305.             if(c==ASSIGN&&(p->z.flags&VAR)&&p->z.flags==p->q1.flags&&p->z.v==p->q1.v&&zleqto(p->z.val.vlong,p->q1.val.vlong)){
  306.                 struct IC *d;
  307.                 if(DEBUG&1024){ printf("removing redundant move:\n");pric2(stdout,p);}
  308.                 changed=1;
  309.                 d=p; p=p->next;
  310.                 if(have_alias){ free(d->use_list); free(d->change_list);}
  311.                 remove_IC(d); continue;
  312.             }
  313.             p=p->next;
  314.         }
  315.         if(changed) done|=changed;
  316.         gchanged|=changed;
  317.     }while(changed);
  318.     return(done);
  319. }
  320.  
  321. void insert_ccs(void)
  322. /*  Fuegt Variablen fuer ccs ein.   */
  323. {
  324.     struct IC *p; struct Var *v; struct Typ *t;
  325.     if(DEBUG&1024) printf("insert_ccs()\n");
  326.     for(p=first_ic;p;p=p->next){
  327.         if(p->code==COMPARE||p->code==TEST){
  328.             p->z.flags=VAR;
  329.             p->z.val.vlong=l2zl(0L);
  330.             t=mymalloc(TYPS);
  331.             t->flags=0;
  332.             t->next=0;
  333.             v=add_var("",t,AUTO,0);
  334.             p->z.v=v;
  335.             p=p->next;
  336.             if(p->code<BEQ||p->code>BGT) ierror(0);
  337.             p->q1.flags=VAR;
  338.             p->q1.val.vlong=l2zl(0L);
  339.             p->q1.v=v;
  340.         }
  341.     }
  342. }
  343.  
  344. #endif
  345. #define FREEAV free(av_globals);free(av_statics);free(av_drefs);free(av_address);
  346. void optimize(long flags,struct Var *function)
  347. /*  flags:   1=Register, 2=optimize, 4=cse/cp, 8=constant_propagation,  */
  348. /*          16=dead_assignments, 32=global-optimizations                */
  349. /*          64=blockweise Registervergabe, 128=loop_optimizations (nur  */
  350. /*             in Verbindung mit 32), 256=recalc_offsets                */
  351. {
  352. #ifndef NO_OPTIMIZER
  353.     struct flowgraph *fg=0;int r,pass=0;
  354.     if(!(c_flags[25]&USEDFLAG)) c_flags_val[25].l=60;
  355.     if(!(c_flags[11]&USEDFLAG)) c_flags_val[11].l=10;
  356.     if(!function) ierror(0);
  357.     norek=nocall=0;
  358.     report_suspicious_loops=report_weird_code=1;
  359.     if(!strcmp(function->identifier,"main")){norek=1;nocall=1;}
  360.     /*  falls main() rekursiv aufgerufen werden kann, muss nomain==0 sein   */
  361.  
  362. #else
  363.  
  364.     flags&=1;
  365.  
  366. #endif
  367.     if(flags&2){
  368. #ifndef NO_OPTIMIZER
  369.         /*  Variablen fuer ccs einsetzen.   */
  370.         if(multiple_ccs&&!(c_flags[24]&USEDFLAG)) insert_ccs();
  371.         /*  nur ein pass, wenn nur lokale Optimierungen */
  372.         if(!(flags&32)) c_flags_val[11].l=1;
  373.         do{
  374.             gchanged=0;pass++;
  375.             av_globals=av_statics=av_address=av_drefs=0;
  376.             rd_globals=rd_statics=rd_address=rd_drefs=0;
  377.             ae_globals=ae_statics=ae_address=ae_drefs=0;
  378.             cp_globals=cp_statics=cp_address=cp_drefs=0;
  379.             dlist=0;vilist=0;elist=0;rd_parms=0;
  380.  
  381.             if(DEBUG&1024) printf("\noptimizer (function %s) pass %d\n",function->identifier,pass);
  382.             num_vars();
  383.             peephole();
  384.             fg=jump_optimization();
  385.             create_alias(fg);
  386.             if(DEBUG&2048) print_vi();
  387.             if(flags&8){
  388.                 do{
  389.                     num_defs();
  390.                     if(flags&32){
  391.                         rd_mode=0;
  392.                         reaching_definitions(fg);
  393.                         if(DEBUG&1024) print_flowgraph(fg);
  394.                     }
  395.                     r=constant_propagation(fg,flags&32);
  396.                     if(DEBUG&1024) {printf("constant_propagation returned %d\n",r);print_flowgraph(fg);}
  397.                     if(r){
  398.                         if(peephole()){free_flowgraph(fg);fg=jump_optimization();}
  399.                     }
  400.                 }while(r);
  401.             }
  402.             if(flags&4){
  403.                 int repeat;
  404.                 do{
  405.                     do{
  406.                         num_exp();
  407.                         if(DEBUG&1024) print_flowgraph(fg);
  408.                         repeat=r=cse(fg,0);    /*  local cse   */
  409.                         if(DEBUG&1024) printf("local cse returned %d\n",r);
  410.                         gchanged|=r;
  411.                         if(r){  /*  neue Variablen eingefuegt   */
  412.                             if(DEBUG&1024) printf("must repeat num_vars\n");
  413.                             free(vilist);
  414.                             FREEAV;
  415.                             num_vars();
  416.                         }
  417.                         do{
  418.                             num_copies();
  419.                             if(DEBUG&1024) print_flowgraph(fg);
  420.                             r=copy_propagation(fg,0);   /*  copy propagation    */
  421.                             if(DEBUG&1024) printf("local copy propagation returned %d\n",r);
  422.                             if(r&2){
  423.                                 if(DEBUG&1024) printf("must repeat num_vars\n");
  424.                                 free(vilist);
  425.                                 FREEAV;
  426.                                 num_vars();
  427.                             }
  428.                             gchanged|=r;repeat|=r;
  429.                         }while(r);
  430.                     }while(repeat);
  431.                     repeat=0;
  432.                     if(flags&32){
  433.                         num_exp();
  434.                         if(DEBUG&1024) print_flowgraph(fg);
  435.                         available_expressions(fg);
  436.                         if(DEBUG&1024) print_flowgraph(fg);
  437.                         r=cse(fg,1);gchanged|=r;repeat|=r;
  438.                         if(DEBUG&1024) printf("global cse returned %d\n",r);
  439.                         if(r){  /*  neue Variablen eingefuegt   */
  440.                             if(DEBUG&1024) printf("must repeat num_vars\n");
  441.                             free(vilist);
  442.                             FREEAV;
  443.                             num_vars();
  444.                             gchanged|=r;repeat|=r;
  445.                             do{
  446.                                 num_copies();
  447.                                 if(DEBUG&1024) print_flowgraph(fg);
  448.                                 r=copy_propagation(fg,0);   /*  copy propagation    */
  449.                                 if(DEBUG&1024) printf("local copy propagation returned %d\n",r);
  450.                                 if(r&2){
  451.                                     if(DEBUG&1024) printf("must repeat num_vars\n");
  452.                                     free(vilist);
  453.                                     FREEAV;
  454.                                     num_vars();
  455.                                 }
  456.                                 gchanged|=r;repeat|=r;
  457.                             }while(r);
  458.                         }
  459.                         num_copies();
  460.                         available_copies(fg);
  461.                         if(DEBUG&1024) print_flowgraph(fg);
  462.                         r=copy_propagation(fg,1);   /*  copy propagation    */
  463.                         if(DEBUG&1024) printf("global copy propagation returned %d\n",r);
  464.                         if(r&2){
  465.                             if(DEBUG&1024) printf("must repeat num_vars\n");
  466.                             free(vilist);
  467.                             FREEAV;
  468.                             num_vars();
  469.                         }
  470.                         gchanged|=r;repeat|=r;
  471.                     }
  472.                 }while(0/*repeat*/);
  473.             }
  474.             if((flags&160)==160){
  475.                 r=loop_optimizations(fg);
  476.                 gchanged|=r;
  477.                 fg=jump_optimization();
  478.             }
  479.             if((flags&16)||((flags&1)&&pass>=c_flags_val[11].l)){
  480. /*                num_vars();*/
  481.                 free_alias(fg);
  482.                 create_alias(fg);
  483.                 active_vars(fg);
  484.                 if(DEBUG&1024) print_flowgraph(fg);
  485.                 if((flags&16)&&pass<=c_flags_val[11].l){
  486.                     r=dead_assignments(fg);
  487.                     if(DEBUG&1024) printf("dead_assignments returned %d\n",r);
  488.                     gchanged|=r;
  489.                 }
  490.             }
  491.  
  492.  
  493.             if((!gchanged||pass>=c_flags_val[11].l)){
  494.             /*  Funktion evtl. fuer inlining vorbereiten und    */
  495.             /*  Registervergabe                                 */
  496.                 int varargs=0,c;
  497.                 if((c=function->vtyp->exact->count)!=0&&(*function->vtyp->exact->sl)[c-1].styp->flags!=VOID)
  498.                     varargs=1;
  499.  
  500.                 /*  default-Wert fuer inline-Entscheidung   */
  501.                 if(!(c_flags[12]&USEDFLAG)) c_flags_val[12].l=30;
  502.                 if(!varargs&&(c_flags[0]&USEDFLAG)&&(c_flags_val[0].l&4096)&&(only_inline||ic_count<=c_flags_val[12].l)){
  503.                 /*  fuer function inlinig vorbereiten   */
  504.                     struct IC *p,*new;
  505.                     if(DEBUG&1024) printf("function <%s> prepared for inlining(ic_count=%d)\n",function->identifier,ic_count);
  506.                     function->fi=mymalloc(sizeof(struct function_info));
  507.                     function->fi->first_ic=first_ic;
  508.                     function->fi->last_ic=last_ic;
  509.                     first_ic=last_ic=0;
  510.                     p=function->fi->first_ic;
  511.                     while(p){
  512.                         new=mymalloc(ICS);
  513.                         memcpy(new,p,ICS);
  514.                         if((p->code>=BEQ&&p->code<=BRA)||p->code==LABEL)
  515.                             new->typf-=lastlabel;
  516.                         add_IC(new);
  517.                         p=p->next;
  518.                     }
  519.                     p=first_ic;first_ic=function->fi->first_ic;function->fi->first_ic=p;
  520.                     p=last_ic;last_ic=function->fi->last_ic;function->fi->last_ic=p;
  521.                     function->fi->vars=0;
  522.                 }
  523.                 if(flags&1){
  524.                     local_regs(fg);
  525.                     if(DEBUG&1024) print_flowgraph(fg);
  526.                     loops(fg,1);
  527.                     if(DEBUG&1024) print_flowgraph(fg);
  528.                     fg=create_loop_headers(fg,1);
  529.                     if(DEBUG&1024) print_flowgraph(fg);
  530.                     fg=create_loop_footers(fg,1);
  531.                     if(DEBUG&1024) print_flowgraph(fg);
  532.                     loop_regs(fg);
  533.                     if(DEBUG&1024) print_flowgraph(fg);
  534. #if 0
  535.                     if(flags&64){
  536.                         block_regs(fg);
  537.                         if(DEBUG&1024) print_flowgraph(fg);
  538.                     }
  539. #endif
  540.                     insert_regs(fg);
  541.                 }
  542.                 if(flags&256) recalc_offsets(fg);
  543.             }
  544.  
  545.             free_alias(fg);
  546.             free_flowgraph(fg);
  547.             free(vilist);
  548.             FREEAV;
  549.  
  550.             if((flags&32)&&gchanged&&pass>=c_flags_val[11].l) error(172,c_flags_val[11].l);
  551.  
  552.         }while(gchanged&&pass<c_flags_val[11].l);
  553.  
  554.         /*  nur, um nochmal ueberfluessige Labels zu entfernen  */
  555.         fg=construct_flowgraph();
  556.         free_flowgraph(fg);
  557.  
  558.         /*  Register bei Funktionsaufrufen sichern  */
  559.         insert_saves();
  560.  
  561. #endif
  562.  
  563.     }else{
  564.         /*  keine Optimierungen     */
  565.         if(flags&1) simple_regs();
  566.         load_simple_reg_parms();
  567.     }
  568.     lastlabel=label;
  569. }
  570.  
  571.